# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
window.Movies =
  loadSubs : (title) ->
    subsPanel = $("#subs .content")
    subsPanel.html("<div class='loading'>正在载入字幕信息...</div>")
    window.shteAPI = new ShteAPI()
    $.getScript "http://shooter.cn/api/qhandler.php?t=sub&e=utf-8&q=#{encodeURIComponent(title)}", () ->
      subsPanel.html("") ;
      if shteAPI.results.length == 0
        subsPanel.html("<div class='no_result'>在 <a href='http://shooter.cn' target='_blank'>射手网</a> 上面没有找到相关的字幕，你可以自己过去再试试。</div>")
      else
        for item in shteAPI.results
          subsPanel.append("<li><a href='http://shooter.cn#{item.link}' target='_blank'>#{item.title}</a>")
    true
  suggest : (el,id,type) ->
    data =
      type : type
    $.post "/movies/#{id}/suggest", data, (res) ->
      $(el).parent().remove()
    return false
class ShteAPI
  results : new Array()
  showResults : () ->
     return false

$(document).ready ->
  $("<img src=\"/code\" id=\"code_img\" />").insertAfter "#user_captcha"
  $("#code_img").click ->
    $("#code_img").attr "src", "/code?tmp=" + new Date().getTime()
    return

  return
